package com.zxl.live.tools.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by Administrator on 2016/7/13.
 */
// CHECKSTYLE:OFF
public abstract class BaseAppCompatFragment extends Fragment {

    private BackHandledInterface mBackHandledInterface;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getActivity() instanceof BackHandledInterface) {
            mBackHandledInterface = (BackHandledInterface) getActivity();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        if (null != mBackHandledInterface) {
            mBackHandledInterface.setSelectedFragment(this);
        }
    }

    public AppCompatActivity getAppCompatActivity() {
        FragmentActivity activity = getActivity();
        if (activity != null && activity instanceof AppCompatActivity) {
            return (AppCompatActivity) activity;
        }
        return null;
    }

    /**
     * 返回事件
     * @return
     */
    public boolean onBackPressed() {
        return false;
    }

    /**
     *
     */
    // CHECKSTYLE:OFF
    public interface BackHandledInterface {

        void setSelectedFragment(BaseAppCompatFragment selectedFragment);
    }

}
